package com.hzjq.encrypt.pop

import android.content.Context
import com.hzjq.encrypt.R
import com.hzjq.encrypt.bean.Sbbhs
import com.hzjq.encrypt.util.KeyBoradX
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import kotlinx.android.synthetic.main.pop_qbq_layout.view.*

class QbqEditorPop : CenterPopupView {

    private lateinit var data: Sbbhs
    private lateinit var c: OnQbqEditorCallback

    constructor(context: Context) : super(context)

    override fun getImplLayoutId(): Int {
        return R.layout.pop_qbq_layout
    }

    override fun onCreate() {
        qbqPopNumberEt.setText(data.sbbh)
        qbqPopCancelText.setOnClickListener {
            hideKeyBord()
            dismiss()
        }

        qbqPopSureText.setOnClickListener {
            hideKeyBord()
            dismiss()
            data.sbbh = qbqPopNumberEt.text.toString()
            c.onQbqEditor(data)
        }
    }

    private fun hideKeyBord(){
        KeyBoradX.hideKeyBoard(qbqPopNumberEt)
    }

    interface OnQbqEditorCallback{
        fun onQbqEditor(sbbhs: Sbbhs)
    }

    companion object {
        fun show(context: Context, c: OnQbqEditorCallback, data: Sbbhs){
            val pop = QbqEditorPop(context)
            if(data != null) {
                pop.data = data
            } else {
                pop.data = Sbbhs()
            }
            pop.c = c
            XPopup.Builder(context)
                .asCustom(pop)
                .show()
        }
    }
}